package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.domain.SgBStoTobOutNotices;
import com.example.demo.service.SgBStoTobOutNoticesService;
import com.example.demo.mapper.SgBStoTobOutNoticesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

/**
* @author OSE000196
* @description 针对表【sg_b_sto_tob_out_notices(TOB出库通知单)】的数据库操作Service实现
* @createDate 2024-10-12 17:54:05
*/
@Service
public class SgBStoTobOutNoticesServiceImpl extends ServiceImpl<SgBStoTobOutNoticesMapper, SgBStoTobOutNotices>
    implements SgBStoTobOutNoticesService{

    @Autowired
    SgBStoTobOutNoticesMapper sgBStoTobOutNoticesMapper;

    private ThreadLocal<List<SgBStoTobOutNotices>> threadLocal = new ThreadLocal<>();

    @Override
    public SgBStoTobOutNotices queryByBillNo(String billNo) {
        System.out.println("SgBStoTobOutNoticesServiceImpl：" + Thread.currentThread().getName());
        List<SgBStoTobOutNotices> sgBStoTobOutNotices = sgBStoTobOutNoticesMapper.selectList(new LambdaQueryWrapper<SgBStoTobOutNotices>().eq(SgBStoTobOutNotices::getBillNo, billNo));
        return sgBStoTobOutNotices.get(0);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateNotices(long l) throws InterruptedException {
        Thread.sleep(300000000000000000L);
        updateInfo(1, "2", true);
        int testTransaction = sgBStoTobOutNoticesMapper.update(new SgBStoTobOutNotices(), new LambdaUpdateWrapper<SgBStoTobOutNotices>().eq(SgBStoTobOutNotices::getId, l).set(SgBStoTobOutNotices::getRemark, "testTransaction"));
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return testTransaction;
    }

    public void updateInfo(int i, String number, boolean b) {
        int testTransaction = sgBStoTobOutNoticesMapper.update(new SgBStoTobOutNotices(), new LambdaUpdateWrapper<SgBStoTobOutNotices>().eq(SgBStoTobOutNotices::getId, 1).set(SgBStoTobOutNotices::getRemark, "testTransaction"));
    }
}




